package leetcode_1401_1500;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_1424 {
    public static void main(String[] args) {

    }
    private static int[] findDiagonalOrder(List<List<Integer>> nums) {
        List<int[]> is = new ArrayList<>();
        int n = nums.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < nums.get(i).size(); j++) {
                is.add(new int[]{i, j, nums.get(i).get(j)});
            }
        }
        is.sort((o1, o2) -> {
            int s1 = o1[0] + o1[1];
            int s2 = o2[0] + o2[1];
            if (s1 == s2){
                return o2[0] - o1[0];
            }
            return s1 - s2;
        });
        int[] ans = new int[is.size()];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = is.get(i)[2];
        }
        return ans;
    }
}
